package com.pc.web.orders;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

@Service
public class OrdersService {
	@Autowired
	OrdersDao dao;

	// 쓰기 읽기
	public void read(String orders_payment, ReceiverBeans beans, Model model,
			ReceiverBeans rebeans) {

		// 무통장 신용카드 radio 쓰기
		if (orders_payment.equals("cash")) {
			beans.setOrders_payment("무통장");
		} else if (orders_payment.equals("card")) {
			beans.setOrders_payment("카드");
		}

		// 쓰기
		dao.write(beans);

		// 읽기
		System.out.println("beans="+beans.getOrders_rcode());
		String rcode=beans.getOrders_rcode();
		rebeans = dao.read(rcode);

		// 무통장 신용카드 radio 선택 부분
		if (orders_payment.equals("cash")) {
			model.addAttribute("payType", orders_payment);
		} else if (orders_payment.equals("card")) {
			model.addAttribute("payType", orders_payment);
		}
		model.addAttribute("beans", rebeans);
	}

	// 결제 읽기
	public void payment(String pay, ReceiverBeans beans, Model model) {
		// 읽기
		String rcode = beans.getOrders_rcode();
		beans = dao.payment(rcode);
		model.addAttribute("beans", beans);
	}

	// 최근주문내역(리스트)
	public List<ReceiverBeans> list() {
		return dao.list();
	}

	// 최근주문내역(읽기)
	public void view(String pay, ReceiverBeans beans, Model model) {
		// 읽기
		String rcode = beans.getOrders_rcode();
		beans = dao.payment(rcode);
		model.addAttribute("beans", beans);
	}

}
